package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.SymbolDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-09-23
 */
public interface SymbolMapper extends BaseMapper<SymbolDO> {

    String QUERY_SQL = "SELECT Symbol_ID, Symbol_CompanyID, Symbol_Type, Symbol_Code, Symbol_Name, Symbol_Creator, Symbol_InsertTime, Symbol_Updater, Symbol_UpdateTime, Symbol_Invalid, Symbol_Comments, Symbol_Tel, SUBSTRING(Symbol_Contact,0,50) as symbolContact, Symbol_Heat, 0 as type, 0 as autoBalance, 0 as personal " +
            "FROM TMS_MSymbol " +
            "WHERE Symbol_CompanyID > 0 and Symbol_Type = 2 ";

    /**
     * 线下承运方list
     *
     * @return
     */
    @Select(QUERY_SQL)
    @DataScope(column = "Symbol_CompanyID")
    List<SymbolDO> list();

    /**
     * 根据id获取信息
     *
     * @param id
     * @return
     */
    @Select(QUERY_SQL + " and Symbol_ID = #{id}")
    SymbolDO getById(Long id);

    @Select(QUERY_SQL + " and Symbol_CompanyID = #{tenantId}")
    List<SymbolDO> getByTenantId(Long tenantId);

    @Select("SELECT Symbol_ID FROM TMS_MSymbol WHERE Symbol_InsertTime >= #{startTime} and Symbol_InsertTime <= #{endTime} ")
    List<Long> getByTime(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT Symbol_ID FROM TMS_MSymbol WHERE Symbol_CompanyID = #{tenantId} and Symbol_InsertTime >= #{startTime} and Symbol_InsertTime <= #{endTime} ")
    List<Long> getByTenantIdTime(@Param("tenantId") Long tenantId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
